import 'package:flutter/material.dart';

class WidgetUtil {
  static RenderObject? renderObject(GlobalKey globalKey) {
    if (globalKey.currentContext == null) {
      throw 'globalKey.currentContext is null';
    }
    return globalKey.currentContext?.findRenderObject();
  }

  static double? x(GlobalKey globalKey) {
    return renderObject(globalKey)?.getTransformTo(null).getTranslation().x;
  }

  static double? y(GlobalKey globalKey) {
    return renderObject(globalKey)?.getTransformTo(null).getTranslation().y;
  }

  static Size? size(GlobalKey globalKey) {
    return renderObject(globalKey)?.paintBounds.size;
  }

  static Rect? paintBounds(GlobalKey globalKey) {
    return renderObject(globalKey)?.paintBounds;
  }

  static double? height(GlobalKey globalKey) {
    return renderObject(globalKey)?.paintBounds.size.height;
  }

  static double? width(GlobalKey globalKey) {
    return renderObject(globalKey)?.paintBounds.size.width;
  }
}
